﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alison.Tools.HttpContact
{
    public class HttpHelper
    {

        /// <summary>
        /// 获取web客户端ip
        /// </summary>
        /// <returns></returns>
        public static string GetWebClientIp()
        {
            string userIP = "未获取用户IP";

            try
            {
                var ip = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
   .Select(p => p.GetIPProperties())
   .SelectMany(p => p.UnicastAddresses)
   .Where(p => p.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && !System.Net.IPAddress.IsLoopback(p.Address))
   .FirstOrDefault()?.Address.ToString();
                return ip;
            }
            catch { }
            return userIP;
        }
    }
}
